import { useSelector } from 'react-redux'
import { StateType } from '../store'
import { ComponentsStateType } from '../store/componentsReducer'

function useGetComponentsInfo() {
  const components = useSelector<StateType>(
    (state: StateType) => state.components
  ) as ComponentsStateType
  const { componentList = [], selectedId = '', copiedComponent = null } = components

  const selectComponent = componentList.find(c => c.fe_id === selectedId)

  return { componentList, selectedId, selectComponent, copiedComponent }
}

export default useGetComponentsInfo
